﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NoteManger.TWorkNoteItem>" %>

<asp:Content ContentPlaceHolderID="PageTitle" runat="server">
    <% if (Model == null)
       { %>写日志<%}
       else
       { %><%:Model.NoteTopic %><%} %>
</asp:Content>
<asp:Content ContentPlaceHolderID="StyleContent" runat="server">
    <link type="text/css" rel="stylesheet" href="<%:Url.Content("~/Content/bootstrap/ext/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css") %>" />
    <%--<link type="text/css" rel="stylesheet" href="<%:Url.Content("~/Content/bootstrap/ext/bootstrap-datetimepicker/css/datepicker.css") %>" />--%>
    <style type="text/css">
        label.control-label {
            text-align: right;
            padding-right: 5px;
        }

        .form-group div {
            padding-left: 5px;
        }

        div.bootstrap-datetimepicker-widget {
            color: #373737;
        }

        span.input-group-addon {
            cursor: pointer;
        }
    </style>
</asp:Content>
<asp:Content ContentPlaceHolderID="ViewTitle" runat="server">
    <%: Model == null ? "写日志" : "日志编辑" %>
</asp:Content>
<asp:Content ContentPlaceHolderID="ViewContent" runat="server">
    <div style="width: 94%; padding-top: 5px;">
        <form class="form-horizontal" role="form" action='<%:Url.Action("Save","Note") %>' method="post" data-need-validate="true" data-error-label="#formErrorLabel">
            <%: Html.AntiForgeryToken() %>
            <%: Html.HiddenFor(model => model.NoteID) %>
            <%: Html.HiddenFor(model => model.NoteState) %>
            <%: Html.HiddenFor(model => model.AuditDate) %>
            <%: Html.HiddenFor(model => model.Auditor) %>
            <%: Html.HiddenFor(model => model.AuditTime) %>
            <%: Html.HiddenFor(model => model.AuditWorkLoad) %>
            <%: Html.HiddenFor(model => model.NoteIndex) %>
            <div class="form-group">
                <label class="col-xs-3 control-label">&nbsp;</label>
                <div class="col-xs-9">
                    <a class="btn btn-info" href='Edit?ed=<%:ViewBag.PrevDay%>'>前一天</a>
                    &nbsp;
                    <a class="btn btn-info" href='Edit?ed=<%:ViewBag.NextDay%>'>后一天</a>
                    &nbsp;
                    &nbsp;
                    <span style="color: red;"><%:Model != null && Model.NoteState == "1" ?  "审核: " + Model.Auditor + "," + Model.AuditDate + " " + Model.AuditTime : string.Empty%></span>
                </div>
            </div>
            <div class="form-group">
                <label for="NoteDate" class="col-xs-3 control-label">日期</label>
                <div class="input-group col-xs-9 datetimepicker" id="dtpNoteDate" style="padding-left: 5px; padding-right: 15px;">
                    <input type="text" id="NoteDate" name="NoteDate" class="form-control" data-format="yyyy-MM-dd" value="<%:(Model == null ? MvcHtmlString.Create(string.IsNullOrWhiteSpace(Convert.ToString(ViewBag.EditDay)) ? DateTime.Now.ToString("yyyy-MM-dd") : Convert.ToString(ViewBag.EditDay)) : Html.ValueFor(model => model.NoteDate)) %>" required="true" data-msg-required="必须输入日期。" />
                    <span class="input-group-addon glyphicon glyphicon-calendar" style="top: 0px;"></span>
                </div>
            </div>
            <div class="form-group">
                <label for="NoteTopic" class="col-xs-3 control-label">主题</label>
                <div class="col-xs-9">
                    <input type="text" class="form-control" id="NoteTopic" name="NoteTopic" value="<%:Html.ValueFor(model => model.NoteTopic) %>" required="true" data-msg-required="必须输入主题。" />
                </div>
            </div>
            <div class="form-group">
                <label for="WorkLoad" class="col-xs-3 control-label">工作量</label>
                <div class="col-xs-9">
                    <input type="number" class="form-control" id="WorkLoad" name="WorkLoad" value="<%:Model == null ? MvcHtmlString.Create("8") : Html.ValueFor(model => model.WorkLoad) %>" required="true" min="0" max="23.9" data-msg-required="必须输入正确工作量。" />
                </div>
            </div>
            <div class="form-group">
                <label for="BeginTime" class="col-xs-3 control-label">开始时间</label>
                <div class="input-group col-xs-9 datetimepicker" id="dtpBeginTime" style="padding-left: 5px; padding-right: 15px;">
                    <input type="text" id="BeginTime" name="BeginTime" class="form-control" data-format="hh:mm:ss" value="<%:Model == null ? MvcHtmlString.Create("08:30:00") : Html.ValueFor(model => model.BeginTime) %>" required="true" data-msg-required="必须输入开始时间。" />
                    <span class="input-group-addon glyphicon glyphicon-time" style="top: 0px;"></span>
                </div>
            </div>
            <div class="form-group">
                <label for="EndTime" class="col-xs-3 control-label">结束时间</label>
                <div class="input-group col-xs-9 datetimepicker" id="dtpEndTime" style="padding-left: 5px; padding-right: 15px;">
                    <input type="text" class="form-control" id="EndTime" name="EndTime" data-format="hh:mm:ss" value="<%:Model == null ? MvcHtmlString.Create("17:00:00") : Html.ValueFor(model => model.EndTime) %>" required="true" data-msg-required="必须输入结束时间。" />
                    <span class="input-group-addon glyphicon glyphicon-time" style="top: 0px;"></span>
                </div>
            </div>
            <div class='form-group'>
                <label for="TaskID" class="col-xs-3 control-label">分类</label>
                <div class="col-xs-9 controls">
                    <select class="form-control" id="TaskID" name="TaskID" onchange="categoryChanged(this);">
                        <%var categories = (Tuple<string, string>[])ViewData["NoteCategories"]; %>
                        <%foreach (Tuple<string, string> item in categories)
                          { %>
                        <option value='<%:(item.Item1 + "_" + item.Item2) %>' <%: Model != null && Model.TaskID == Convert.ToString(item.Item1) ? "selected" : string.Empty%>><%: item.Item2 %></option>
                        <%} %>
                    </select>
                </div>
            </div>
            <div class="form-group<%:Model!=null && Model.TaskID == NoteManger.TWorkNoteItem.TASK_TYPE_WORKSITE ? string.Empty : " hidden" %>" id="locationContainer">
                <label class="control-label col-xs-3">地点</label>
                <div class="controls col-xs-9">
                    <div class="col-xs-3" style="padding-left: 0px; padding-right: 0px;">
                        <select class="form-control" name="Province" onchange="loadCitys(this.value);">
                            <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                            <%var provinces = (Tuple<string, string, string>[])ViewData["Provinces"]; %>
                            <%foreach (Tuple<string, string, string> item in provinces)
                              { %>
                            <option value='<%:(item.Item1 +"_"+ item.Item2) %>' <%: Model != null && Model.Province == Convert.ToString(item.Item2) ? "selected" : string.Empty%>><%: item.Item2 %></option>
                            <%} %>
                        </select>
                    </div>
                    <div class="col-xs-3" style="padding-left: 0px; padding-right: 0px;">
                        <select class="form-control" id="City" name="City">
                            <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                        </select>
                    </div>
                    <div class="col-xs-6" style="padding-left: 0px; padding-right: 0px;">
                        <input type="text" class="form-control" id="Hospital" name="Hospital" value="<%:Html.ValueFor(model => model.Hospital) %>" conditional="if($('#TaskID').val().indexOf('<%:NoteManger.TWorkNoteItem.TASK_TYPE_WORKSITE %>_') == 0 && (!'{value}' || !$.trim('{value}'))) return false;" data-msg-conditional="请输入医院名称。" />
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="NoteBody" class="col-xs-3 control-label">工作内容</label>
                <div class="col-xs-9">
                    <textarea class="form-control" rows="5" id="NoteBody" name="NoteBody" required="true" data-msg-required="必须输入工作内容。"><%:Html.ValueFor(model => model.NoteBody) %></textarea>
                </div>
            </div>
            <input type="submit" id="btnSubmit" class="hidden" />
        </form>
    </div>
</asp:Content>
<asp:Content ContentPlaceHolderID="ViewFooter" runat="server">
    <div class="row">
        <div class="col-xs-9 text-left">
            <div id="formErrorLabel" class="validation-summary-errors"><%--<%: Html.ValidationSummary(true) %>--%></div>
        </div>
        <div class="col-xs-3 text-right">
            <%if (Model == null || Model.NoteState != "1")
              { %>
            <a class="btn btn-success" href="javascript:void(0)" onclick="if($(document.forms[0]).trigger('submit'));"><i class="cus-icon-save"></i>保存</a>
            <%} %>
        </div>
    </div>
</asp:Content>
<asp:Content ContentPlaceHolderID="ScriptContent" runat="server">
    <%--<script type="text/javascript" src='<%:Url.Content("~/Content/bootstrap/ext/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js") %>'></script>--%>
    <script type="text/javascript" src='<%:Url.Content("~/Content/bootstrap/ext/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js") %>'></script>
    <script type="text/javascript" src='<%:Url.Content("~/Content/bootstrap/ext/bootstrap-datetimepicker/js/bootstrap-datetimepicker.lang.zh-cn.js") %>'></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("div[class*='datetimepicker']").each(function (index, el) {
                var options = {
                    format: "yyyy-MM-dd",
                    language: "zh-cn",
                    pickTime: false,
                    pickDate: true,
                    pick12HourFormat: false
                };
                options.format = $(this).children(":first").data("format") || options.format;
                options.pickDate = !(options.pickTime = (options.format.indexOf("HH") >= 0 || options.format.indexOf("mm") >= 0 || options.format.indexOf("ss") >= 0))
                $(this).datetimepicker(options);
            });
        });
        function loadCitys(province, city) {
            var control = $("#City");
            control.html("<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>");
            if (!province || !$.trim(province)) return;
            var provinceCode = province.split("_")[0];
            request('<%:Url.Action("ProvinceCitys","Note")%>', { provinceCode: provinceCode }, function (result) {
                if (!!result.data && result.data.length > 0) {
                    for (var i = 0; i < result.data.length; i++) $("<option " + (!!city && $.trim(city) == result.data[i] ? "selected" : "") + ">").text(result.data[i]).appendTo(control);
                }
            });
        }
        function categoryChanged(sender) {
            if (sender.value.indexOf('<%:NoteManger.TWorkNoteItem.TASK_TYPE_WORKSITE %>_') == 0) {
                $("#locationContainer").removeClass("hidden");
            }
            else {
                var container = $("#locationContainer");
                if (!container.hasClass("hidden")) container.addClass("hidden");
                container.find("select").each(function () {
                    this.selectedIndex = 0;
                });
                container.find("input").val("");
            }
        }
    </script>
    <%= Model != null ? "<script type=\"text/javascript\">$(document).ready(function(){loadCitys($(\"select[name='Province']\").val(),\"" + Model.City + "\");});</script>" : string.Empty%>
</asp:Content>
